package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.service.GoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: Gavin
 * @Date: 9/11/2023 4:54 PM
 */
@RequestMapping("/goodsType")
@Api(tags = "商品分类查询")
@RestController
public class GoodsTypeController {
    @Autowired
    GoodsTypeService goodsTypeService;
    @ApiOperation("查询商品的所有的分类")
    @PostMapping("loadGoodsType")
    public String queryGoodsCategory(){
        return JSON.toJSONString(goodsTypeService.queryGoodsCategory());
        // return "{\"attributes\":{\"state\":1},\"children\":[{\"attributes\":{\"state\":1},\"children\":[{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":6,\"state\":\"open\",\"text\":\"连衣裙\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":7,\"state\":\"open\",\"text\":\"男士西装\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":8,\"state\":\"open\",\"text\":\"牛仔裤\"}],\"iconCls\":\"goods-type\",\"id\":2,\"state\":\"closed\",\"text\":\"服饰\"},{\"attributes\":{\"state\":1},\"children\":[{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":9,\"state\":\"open\",\"text\":\"进口食品\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":10,\"state\":\"open\",\"text\":\"地方特产\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":11,\"state\":\"open\",\"text\":\"休闲食品\"}],\"iconCls\":\"goods-type\",\"id\":3,\"state\":\"closed\",\"text\":\"食品\"},{\"attributes\":{\"state\":1},\"children\":[{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":12,\"state\":\"open\",\"text\":\"电视机\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":13,\"state\":\"open\",\"text\":\"洗衣机\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":14,\"state\":\"open\",\"text\":\"冰箱\"}],\"iconCls\":\"goods-type\",\"id\":4,\"state\":\"closed\",\"text\":\"家电\"},{\"attributes\":{\"state\":1},\"children\":[{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":15,\"state\":\"open\",\"text\":\"相机\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":16,\"state\":\"open\",\"text\":\"手机\"},{\"attributes\":{\"state\":0},\"children\":[],\"iconCls\":\"goods-type\",\"id\":17,\"state\":\"open\",\"text\":\"音箱\"}],\"iconCls\":\"goods-type\",\"id\":5,\"state\":\"closed\",\"text\":\"数码\"}],\"iconCls\":\"goods-type\",\"id\":1,\"state\":\"closed\",\"text\":\"所有类别\"}";
    }
    @ApiOperation("新增分类")
    @PostMapping("save")
    public ServiceVO saveCategory(@RequestParam("goodsTypeName")String goodsTypeName,
                                  @RequestParam("pId")Integer pId){
        goodsTypeService.save(goodsTypeName,pId);
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    @ApiOperation("删除分类")
    @PostMapping("delete")
    public ServiceVO deleteById(@RequestParam("goodsTypeId")Integer goodsTypeId){

        return goodsTypeService.deleteById(goodsTypeId);
    }
}
